package momo.multitree.structure;

public class Node
{
	private final String id;
	private double workloadRate;
	private double stability;
	
	/**
	 * Constructor of Node.
	 * @param id Unique identifier of the Node
	 * @param workloadRate Rate of work done. Consider as work done / total work done
	 * @param stability Determines the disconnectivity of the node. Consider as rate of disconnectivity of the node * total no of direct children 
	 */
	public Node(String id, double workloadRate, double stability)
	{
		this.id = id;
		this.workloadRate = workloadRate;
		this.stability = stability;
	}
	
	public boolean compareById(Node n)
	{
		if ( n.getId().equals(id) )
			return true;
		return false;
	}
	
	public boolean compare(Node n)
	{
		return compareById(n) && n.getStability()==getStability() && n.getWorkloadRate()==getWorkloadRate();
	}

	public String getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Node other = (Node) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public double getWorkloadRate() {
		return workloadRate;
	}

	public void setWorkloadRate(double workloadRate) {
		this.workloadRate = workloadRate;
	}

	public double getStability() {
		return stability;
	}

	public void setStability(double stability) {
		this.stability = stability;
	}
	
	public Node clone()
	{
		return new Node(id, workloadRate, stability);
	}
	
	public String toString()
	{
		return "Node: id-"+id+", workloadRate-"+workloadRate+", stability-"+stability;
	}
}//end of class Node
